package com.ljx.List;

import com.ljx.Dynamic.ListNode;

import java.util.PriorityQueue;

/**
 * @author 李加喜
 * @Package com.ljx.Dynamic
 * @date 2021-11-04 23:12
 */
// 合并列表
public class MergeTwoLists {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        PriorityQueue priorityQueue = new PriorityQueue();
        ListNode dp = new ListNode(-1);
        ListNode p=dp;
        ListNode p1=l1,p2=l2;
        while (p1!=null && p2!=null){
            if (p1.val>p2.val){
                p.next=p2;
                p2=p2.next;
            }else {
                p.next=p1;
                p1=p1.next;
            }
            p=p.next;
        }
        if (p1 != null){
            p.next=p1;
        }
        if (p2!=null){
            p.next=p2;
        }
        return dp.next;
    }
}
